<?php

class UserManager extends Manager
{
	const PK_NAME = 'email';
	const TABLE_NAME = 'uzytkownicy';
	const OBJECT_NAME = 'User';

	public function getByEmail($email)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('email = ?', $email);
		return $this->_fetchObject(self::OBJECT_NAME, $select);
	}
	
	public function getNormalUsers()
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('rola = ?', User::ROLE_USER)
					->order('email asc');
		
		return $this->_fetchCollection(self::OBJECT_NAME, $select);
	}
	
	public function authenticateUser($email, $hash)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('email = ?', $email)
					->where('haslo = ?', $hash)
					->where('aktywny = ?', 1);
		
		return $this->_fetchObject(self::OBJECT_NAME, $select);
	}
}